package com.sinai.mshab.format;

import com.google.gwt.junit.client.GWTTestCase;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.sinai.mshab.format.validation.Validator;

public class GwtTestFormatPanel extends GWTTestCase {

	private FormatPanel formatPanel;
	
	@Override
	protected void gwtSetUp() throws Exception {
		super.gwtSetUp();
		formatPanel = new FormatPanel();
	}

	public void testAddValidator() {

		TextBox textBox = new TextBox();
		Validator<TextBox> textBoxValidator = new MockValidator();
		formatPanel.addValidator(textBox, textBoxValidator);
		
		// make sure the widget was added to the formatPanel.
		assertEquals(textBox, textBoxValidator.getWidget());
		
		// make sure that formatPanel is an observer of the validator.
		assertEquals(1, textBoxValidator.countObservers());
		textBoxValidator.deleteObserver(formatPanel);
		assertEquals(0, textBoxValidator.countObservers());
	}
	
	@Override
	public String getModuleName() {
		return "com.sinai.mshab.mshabFormat";
	}

}
